package com.waitingsnow.core.base
{
import com.waitingsnow.core.debug.LogOutput;
import com.waitingsnow.core.debug.Logger;
import com.waitingsnow.core.debug.States;

import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageQuality;
import flash.display.StageScaleMode;
import flash.events.Event;

/**
 * 
 * @author waitingsnow
 * $Id: BaseMobieSprite.as 2 2012-05-17 10:10:03Z cgslendy@gmail.com $
 */
public class BaseMobieSprite extends Sprite
{
	//==========================================================================
	//  Constructor
	//==========================================================================
	/**
	 * Constructs a new <code>BaseMobieSprite</code> instance.
	 * 
	 */
	public function BaseMobieSprite()
	{
		if (stage)
		{
			initDisplay();
		}
		else
		{
			addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
		}
	}
	
	//==========================================================================
	//  Variables
	//==========================================================================
	private var logOutPut:LogOutput;
	
	//==========================================================================
	//  Methods
	//==========================================================================
	protected function initDisplay():void
	{
		initSystemSet();
	}
	
	protected function initSystemSet():void
	{
		stage.align = StageAlign.TOP_LEFT;
		stage.scaleMode = StageScaleMode.NO_SCALE;
		stage.quality = StageQuality.HIGH;
	}
	
	protected function initDebugInfo(debug:Boolean = false):void
	{
		if (!logOutPut)
		{
			LogOutput.fontSize = 14;
			logOutPut = new LogOutput();
			addChild(logOutPut);
		}
		logOutPut.logLevel = debug ? Logger.LEVEL_DEBUG : Logger.LEVEL_INFO;
		if (debug)
		{
			States.fontSize = 10;
			addChild(new States());
		}
	}
	
	//==========================================================================
	//  Event Handlers
	//==========================================================================
	private function addedToStageHandler(event:Event):void
	{
		removeEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
		initDisplay();
	}
}
}